// 公共js
let Base64 = require('js-base64').Base64
export default {
  install (Vue, options) {
    // 文件预览
    Vue.prototype.$previewFile = function (url) {
      // 线下
      // let origin = process.env.NODE_ENV === 'development' ? 'http://192.168.1.50:9026' : window.location.origin
      // let fileUrl = origin + '/file/' + url
      // let previewUrl = origin + '/preview/onlinePreview?url=' + fileUrl
      
      // 线上
      let o = encodeURIComponent(Base64.encode('http://118.122.86.3:8888/group1/' + url)) //线上
      let previewUrl = 'http://118.122.86.3:8012/onlinePreview?url=' + o

      window.open(previewUrl)
    }
    // 文件下载
    Vue.prototype.$downloadFile = function (url, name) {
      // 线下
      // let origin = process.env.NODE_ENV === 'development' ? 'http://192.168.1.50:9026' : window.location.origin
      // let downloadUrl = origin + '/download/' + url + '?attname=' + name

      // 线上
      url = url.slice(4)
      let origin = process.env.NODE_ENV === 'development' ? 'http://118.122.86.3:8200' : 'http://118.122.86.3:8200'
      let downloadUrl = origin + '/data/' + url + '?attname=' + name
      window.open(downloadUrl)
    }
  }
}
